//
//  HomePageViewController.m
//  drug
//
//  Created by 沈鑫 on 16/4/5.
//  Copyright © 2016年 沈鑫. All rights reserved.
//

#import "HomePageViewController.h"
#import "HomePageTableViewCell.h"
#import "HomeModel.h"
#import "RequestManager.h"
#import "HomeImageViewController.h"
#import "PharmacyViewController.h"
#import "FourButtonViewController.h"
#import "ClassificationViewController.h"
#import "UMSocial.h"
#import "FMDB.h"
#import "ConsultViewController.h"
#import "RemindViewController.h"
#import "SweepViewController.h"
#import "MyTabBarViewController.h"
#import <CoreLocation/CoreLocation.h>
@interface HomePageViewController ()<UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate,CLLocationManagerDelegate>

// 地图
@property (nonatomic, strong)CLLocationManager *locationManager;
@property (nonatomic, strong)CLGeocoder *_geocoder;;
// 属性
@property (nonatomic, strong)UIView *lView;

@property (nonatomic, strong)UITableView *tableView;

@property (nonatomic, strong)UIView *hadeView;

@property (nonatomic, strong)UIView *footView;

@property (nonatomic, strong)UIScrollView *hadeScrollView;

@property (nonatomic, strong)UIButton *button1;
@property (nonatomic, strong)UILabel *label1;

@property (nonatomic, strong)UIButton *button2;
@property (nonatomic, strong)UILabel *label2;

@property (nonatomic, strong)UIButton *button3;
@property (nonatomic, strong)UILabel *label3;

@property (nonatomic, strong)UIButton *button4;
@property (nonatomic, strong)UILabel *label4;

@property (nonatomic, strong)UIView *headerView;

@property (nonatomic, strong)NSMutableArray *myArray;
@property (nonatomic, strong)NSMutableArray *sqliteArray;

@property (nonatomic,strong)NSMutableDictionary *dic1;

@property (nonatomic, strong)NSTimer *timer;

@property (nonatomic, strong)UIImageView *homeImageView;

@property (nonatomic, strong)UIImageView *vitaminImageView;

@property (nonatomic, strong)NSIndexPath *indexPath;

@property (nonatomic, assign)NSInteger row;

// 专门用来判断家庭用药和维生素的
@property (nonatomic, assign)BOOL isOneOrTow;

@property (nonatomic, strong)FMDatabase *db;
@end

@implementation HomePageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
 
    NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)firstObject]stringByAppendingPathComponent:@"drug.db"];
    _db = [FMDatabase databaseWithPath:path];
    if (![_db open])
    {
        NSLog(@"无法打开数据库");
    }
    
    [_db executeUpdate:@"CREATE TABLE drug(_id text, AvgPrice text, TitleImg text, NameCN text, MedCare text, NewOTC text, BaseMed text)"];
    
    [self request];
    [self add];
    
    //定位管理器
    _locationManager=[[CLLocationManager alloc]init];
    
    if (![CLLocationManager locationServicesEnabled]) {
        NSLog(@"定位服务当前可能尚未打开，请设置打开！");
        return;
    }
    
    //如果没有授权则请求用户授权
    if ([CLLocationManager authorizationStatus]==kCLAuthorizationStatusNotDetermined){
        [_locationManager requestWhenInUseAuthorization];
    }else if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusAuthorizedWhenInUse){
        //设置代理
        _locationManager.delegate=self;
        //设置定位精度
        _locationManager.desiredAccuracy=kCLLocationAccuracyBest;
        //定位频率,每隔多少米定位一次
        CLLocationDistance distance=10.0;//十米定位一次
        _locationManager.distanceFilter=distance;
        //启动跟踪定位
        [_locationManager startUpdatingLocation];
    
    }
    
  
    
}

#pragma mark 跟踪定位代理方法，每次位置发生变化即会执行（只要定位到相应位置）
//可以通过模拟器设置一个虚拟位置，否则在模拟器中无法调用此方法
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
    CLLocation *location=[locations firstObject];//取出第一个位置
    CLLocationCoordinate2D coordinate=location.coordinate;//位置坐标
    NSLog(@"经度：%f,纬度：%f,海拔：%f,航向：%f,行走速度：%f",coordinate.longitude,coordinate.latitude,location.altitude,location.course,location.speed);
    //如果不需要实时定位，使用完即使关闭定位服务
    [_locationManager stopUpdatingLocation];
}

#pragma mark --- 插入数据 ---
- (void)addModel
{
    for (HomeModel *model in _myArray)
    {
        // integer类型 需要括号括起来
        [_db executeUpdate:@"INSERT INTO drug(_id, AvgPrice, TitleImg, NameCN, MedCare, NewOTC, BaseMed) VALUES(?, ?, ? ,?, ?, ?, ?)",model._id, model.AvgPrice, model.TitleImg, model.NameCN, model.MedCare, model.NewOTC, model.BaseMed];
    }
}

#pragma mark --- 取出数据 ---
- (NSMutableArray *)getModel;
{
    NSMutableArray *array = [NSMutableArray array];
    FMResultSet *result = [_db executeQuery:@"SELECT *FROM drug"];
    while ([result next])
    {
        HomeModel *model = [[HomeModel alloc]init];
        NSString *_id = [result stringForColumn:@"_id"];
        model._id = _id;
        
        NSString *AvgPrice = [result stringForColumn:@"AvgPrice"];
        model.AvgPrice = AvgPrice;
        
        NSString *TitleImg = [result stringForColumn:@"TitleImg"];
        model.TitleImg = TitleImg;
        
        NSString *NameCN = [result stringForColumn:@"NameCN"];
        model.NameCN = NameCN;
        
        NSString *MedCare = [result stringForColumn:@"MedCare"];
        model.MedCare = MedCare;
        
        NSString *NewOTC = [result stringForColumn:@"NewOTC"];
        model.NewOTC = NewOTC;
        
        NSString *BaseMed = [result stringForColumn:@"BaseMed"];
        model.BaseMed = BaseMed;
        [array addObject:model];
    }
    [result close];
//    NSLog(@"-----------%@",array);
    return array;
}

#pragma mark --- 删除数据 ---
- (void)deleteModel
{
    [_db executeUpdate:@"DELETE FROM drug"];
}


- (void)request
{
    [RequestManager requestWithUrl:@"http://openapi.ypt.langma.cn/yws/?json=%7B%0A%20%20%22op_type%22%20%3A%201003%2C%0A%20%20%22c_ver%22%20%3A%20%224.0.0%22%2C%0A%20%20%22c_type%22%20%3A%200%2C%0A%20%20%22uid%22%20%3A%200%2C%0A%20%20%22cid%22%20%3A%200%0A%7D" requestType:RequestTypeGET parDic:nil finish:^(NSData *data) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        _myArray = [HomeModel getData:dic];
        
        // 先删除再添加
        [self deleteModel];
        [self addModel];
        
        dispatch_async(dispatch_get_main_queue(), ^{
            [_tableView reloadData];
                    });
    } error:^(NSError *error) {
        _sqliteArray = [self getModel];
        _myArray = _sqliteArray;
//        NSLog(@"%ld",_sqliteArray.count);
//        NSLog(@"%ld",_myArray.count);
        dispatch_async(dispatch_get_main_queue(), ^{
            [_tableView reloadData];
        });
    }];
}


#pragma mark --- 自定义分区头 ---
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    _headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KWIDTH, 40)];
    _headerView.backgroundColor = [UIColor clearColor];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 5, KWIDTH, 30)];
    label.textColor = [UIColor blackColor];
    label.text = @"云南白药";
    label.textColor = [UIColor brownColor];
    [_headerView addSubview:label];
    
    UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(KWIDTH - 50, 5, 30, 30)];
    label1.textColor = [UIColor blackColor];
    label1.text = @">";
    [label addSubview:label1];
    
    if (section == 0)
    {
        label.text = @"  感冒用药";
        UITapGestureRecognizer *oneTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(oneTapAction:)];
        label.userInteractionEnabled = YES;
        [label addGestureRecognizer:oneTap];
    }
    else if (section == 1)
    {
        label.text = @"  慢性用药";
        UITapGestureRecognizer *towTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(towTapAction:)];
        label.userInteractionEnabled = YES;
        [label addGestureRecognizer:towTap];
    }

    label.font = [UIFont systemFontOfSize:22];
    label1.font = [UIFont systemFontOfSize:22];
    return _headerView;
}

#pragma matk --- 第一分区手势方法 ---
- (void)oneTapAction:(UITapGestureRecognizer *)tap
{
    ClassificationViewController *class = [[ClassificationViewController alloc]init];
    class.navigationItemTitle = @"感冒用药";
    class.number = 1;
    [self.navigationController pushViewController:class animated:YES];
}

#pragma matk --- 第二分区手势方法 ---
- (void)towTapAction:(UITapGestureRecognizer *)tap
{
    ClassificationViewController *class = [[ClassificationViewController alloc]init];
    class.navigationItemTitle = @"慢性用药";
    class.number = 2;
    [self.navigationController pushViewController:class animated:YES];
}

#pragma mark --- 自定义分区头高度 ---
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 40;
}


// 地址点击方法
- (void)leftAction:(UIBarButtonItem *)barButton
{
    NSLog(@"地址");
}

// 分享方法
- (void)rightAction:(UIBarButtonItem *)barButton
{
    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"www.baidu.com"]];
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:@"55fd0ce3e0f55a305b002070"
                                      shareText:[NSString stringWithFormat:@"我在用药百科看到一篇很好的文章，快来围观医药最新消息~http://www.baidu.%@", data]
                                     shareImage:[UIImage imageWithData:data]
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,UMShareToRenren,UMShareToSms,UMShareToDouban,UMShareToEmail,nil]
                                       delegate:self];
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    
    HomePageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    // 取消cell点击响应
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    // 取消渲染
    cell.selectionStyle = UITableViewCellAccessoryNone;

    
    // cellButton点击方法
    [cell.button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [cell.button1 addTarget:self action:@selector(buttonAction1:) forControlEvents:UIControlEventTouchUpInside];
    if (indexPath.section == 0)
    {
        // i * 2 + 1
        HomeModel *model1 = _myArray[indexPath.row * 2];
        HomeModel *model2 = _myArray[indexPath.row * 2 + 1];
        [cell getModel:model1 modle2:model2];
        return cell;
    }
    else
    {
        HomeModel *model1 = _myArray[4 + indexPath.row * 2];
        HomeModel *model2 = _myArray[4 + indexPath.row * 2 + 1];
        [cell getModel:model1 modle2:model2];
        return cell;
    }
    
}

#pragma mark --- 第一列cell ---
- (void)buttonAction:(UIButton *)button
{
    PharmacyViewController *pharmacy = [[PharmacyViewController alloc]init];
    _row = button.tag - 1;
    HomeModel *model = _myArray[_row];
    
    
    pharmacy.homeModel = model;
//    NSLog(@"%@",pharmacy.homeModel._id);
//    NSLog(@"row===%ld",_row);
    [self.navigationController pushViewController:pharmacy animated:YES];
    
}

#pragma mark --- 第二列cell ---
- (void)buttonAction1:(UIButton *)button
{
    PharmacyViewController *pharmacy = [[PharmacyViewController alloc]init];
    _row = button.tag - 1;
    
    HomeModel *model = _myArray[_row];
    pharmacy.homeModel = model;
    
//    NSLog(@"row===%ld",_row);
    [self.navigationController pushViewController:pharmacy animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 160;
}

- (void)add
{
    self.navigationItem.title = @"用药百科";
    // navigation两边button 的颜色
    [self.navigationController.navigationBar setTintColor:[UIColor blackColor]];
    // navigation字体的颜色 大写 型号
    [self.navigationController.navigationBar setTitleTextAttributes: @{NSFontAttributeName: [UIFont fontWithName:@"Arial-BoldItalicMT" size:19],
    
    
    NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
    // 透明度关闭
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.164 green:0.657 blue:0.915 alpha:1.000];
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KWIDTH, KHEIGHT - 64)];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    [self.view addSubview:_tableView];
    
    // 注册
    [_tableView registerClass:[HomePageTableViewCell class] forCellReuseIdentifier:@"cell"];
    
    self.hadeView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KWIDTH, KHEIGHT / 2 + 50 + 150)];
    UIView *myView = [[UIView alloc]initWithFrame:CGRectMake(KWIDTH / 2, KHEIGHT / 2 + 50 + 20, 1, 110)];
    myView.backgroundColor = [UIColor grayColor];
    [self.hadeView addSubview:myView];
    
    UIView *myView1 = [[UIView alloc]initWithFrame:CGRectMake(0, KHEIGHT / 2 + 50 + 20 - 2, KWIDTH, 1)];
    myView1.backgroundColor = [UIColor grayColor];
    [self.hadeView addSubview:myView1];
    
    UIView *myView2 = [[UIView alloc]initWithFrame:CGRectMake(0, KHEIGHT / 2 + 50 + 20 + 110 - 1, KWIDTH, 1)];
    myView2.backgroundColor = [UIColor grayColor];
    [self.hadeView addSubview:myView2];
    
    // 家庭图片
    _homeImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, KHEIGHT / 2 + 50 + 20 - 1, KWIDTH / 2 - 1, 110)];
    _homeImageView.image = [UIImage imageNamed:@"jiating"];
    _homeImageView.userInteractionEnabled = YES;
    [self.hadeView addSubview:_homeImageView];
    
    // 添加手势
    UITapGestureRecognizer *homeTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(homeTapAction:)];
    
    [self.homeImageView addGestureRecognizer:homeTap];
 
    
    // 维生素图片
    _vitaminImageView = [[UIImageView alloc]initWithFrame:CGRectMake(KWIDTH / 2 + 1, KHEIGHT / 2 + 50 + 20 - 1, KWIDTH / 2, 110)];
    _vitaminImageView.image = [UIImage imageNamed:@"wss"];
    [self.hadeView addSubview:_vitaminImageView];
    _vitaminImageView.userInteractionEnabled = YES;
    // 添加手势
    UITapGestureRecognizer *vitaminTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(vitaminTapTapAction:)];
    [self.vitaminImageView addGestureRecognizer:vitaminTap];

    // 表头大图片
    NSArray *array = @[@"t1",@"she",@"jiating",@"wss",@"cheshi_meitu_1"];
    self.hadeScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, KWIDTH, KHEIGHT / 2 - 70)];
    _hadeScrollView.pagingEnabled = YES;
    _hadeScrollView.delegate = self;
    _hadeScrollView.bounces = NO;
    _hadeScrollView.contentOffset = CGPointMake(KWIDTH, 0);
    _hadeScrollView.showsHorizontalScrollIndicator = NO;
    _hadeScrollView.contentSize = CGSizeMake(KWIDTH * array.count + 2, KHEIGHT / 2 - 70);
    for (int i = 0; i < array.count + 2; i++)
    {
        UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(KWIDTH * i, 0, KWIDTH, KHEIGHT / 2 - 70)];
        NSInteger index = array.count - 1;
        if (i > 0)
        {
            index = (i - 1) % array.count;
        }
        image.image = [UIImage imageNamed:array[index]];
        [_hadeScrollView addSubview:image];
    }
     [self.hadeView addSubview:_hadeScrollView];
    
    _timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(timerAction:) userInfo:nil repeats:YES];
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        [[NSRunLoop currentRunLoop]addTimer:_timer forMode:NSDefaultRunLoopMode];
        [[NSRunLoop currentRunLoop]run];
    });
    
    /*
     四个Btuuon
     */
    _button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    _button1.frame = CGRectMake((KWIDTH - 240) / 5, KHEIGHT / 2 - 50, 60, 60);
    [_button1 setImage:[UIImage imageNamed:@"scan_64"]
              forState:UIControlStateNormal];
    [_button1 addTarget:self action:@selector(oneButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    _button1.layer.cornerRadius = 30;
    _button1.layer.masksToBounds = YES;
    [self.hadeView addSubview:_button1];
    
    _label1 = [[UILabel alloc]initWithFrame:CGRectMake((KWIDTH - 240) / 5 - 5, (KHEIGHT / 2) + 20, 70, 20)];
    _label1.textColor = [UIColor blackColor];
    _label1.text = @"扫码找药";
    [self.hadeView addSubview:_label1];
    
    _button2 = [UIButton buttonWithType:UIButtonTypeCustom];
    _button2.frame = CGRectMake((KWIDTH - 240) / 5 * 2 + 60, KHEIGHT / 2 - 50, 60, 60);
    [_button2 setImage:[UIImage imageNamed:@"Chat_64"] forState:UIControlStateNormal];
    [_button2 addTarget:self action:@selector(towButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    _button2.layer.cornerRadius = 30;
    [self.hadeView addSubview:_button2];
    _label2 = [[UILabel alloc]initWithFrame:CGRectMake((KWIDTH - 240) / 5 * 2 + 60 - 5, (KHEIGHT / 2) + 20, 70, 20)];
    _label2.textColor = [UIColor blackColor];
    _label2.text = @"用药咨询";
    [self.hadeView addSubview:_label2];
    
    _button3 = [UIButton buttonWithType:UIButtonTypeCustom];
    _button3.frame = CGRectMake((KWIDTH - 240) / 5 * 3 + 60 * 2, KHEIGHT / 2 - 50, 60, 60);
    [_button3 setImage:[UIImage imageNamed:@"Alarm_"] forState:UIControlStateNormal];
    [_button3 addTarget:self action:@selector(threeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    _button3.layer.cornerRadius = 30;
    [self.hadeView addSubview:_button3];
    _label3 = [[UILabel alloc]initWithFrame:CGRectMake((KWIDTH - 240) / 5 * 3 + 60 * 2 - 5, (KHEIGHT / 2) + 20, 70, 20)];
    _label3.textColor = [UIColor blackColor];
    _label3.text = @"服药提醒";
    [self.hadeView addSubview:_label3];
    
    _button4 = [UIButton buttonWithType:UIButtonTypeCustom];
    _button4.frame = CGRectMake((KWIDTH - 240) / 5 * 4 + 60 * 3 - 10, KHEIGHT / 2 - 50, 80, 60);
    [_button4 setImage:[UIImage imageNamed:@"document"] forState:UIControlStateNormal];
    _button4.layer.cornerRadius = 30;
    [_button4 addTarget:self action:@selector(fourButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.hadeView addSubview:_button4];
    _label4 = [[UILabel alloc]initWithFrame:CGRectMake((KWIDTH - 240) / 5 * 4 + 60 * 3 - 5, (KHEIGHT / 2) + 20, 70, 20)];
    _label4.textColor = [UIColor blackColor];
    _label4.text = @"药品搜索";
    [self.hadeView addSubview:_label4];
    
   
    // 地址Button
    _leftBarButton = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"ic_tabbar_local_selected"] style:UIBarButtonItemStylePlain target:self action:@selector(leftAction:)];
  //  [leftBarButton setTintColor: [UIColor grayColor]];
    self.navigationItem.leftBarButtonItem = _leftBarButton;
    
    // 二维码Button
    _rightBarButton = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"tripview_share_highlight"] style:UIBarButtonItemStylePlain target:self action:@selector(rightAction:)];

  //  [rightBarButton setTintColor: [UIColor blackColor]];
    self.navigationItem.rightBarButtonItem = _rightBarButton;
    
    // 添加表头
    [self.tableView setTableHeaderView:_hadeView];
    // 添加表尾
    self.footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KWIDTH, (KHEIGHT - 44) / 2 + 30)];
    [self.tableView setTableFooterView:_footView];
    
    _lView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KWIDTH, 29)];
    _lView.backgroundColor = [UIColor clearColor];
    [self.footView addSubview:_lView];
    
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 2, 150, 25)];
    titleLabel.text = @"合作品牌";
    titleLabel.textColor = [UIColor brownColor];
    [_footView addSubview:titleLabel];
    
    UILabel *aLabel = [[UILabel alloc]initWithFrame:CGRectMake(KWIDTH - 50, 2, 30, 25)];
    aLabel.text = @">";
    aLabel.textColor = [UIColor blackColor];
    [_footView addSubview:aLabel];
    
    
    _lView = [[UIView alloc]initWithFrame:CGRectMake(0, 30, KWIDTH, 1)];
    _lView.backgroundColor = [UIColor lightGrayColor];
    [self.footView addSubview:_lView];
    
    [self.tableView setTableFooterView:_footView];
    _lView = [[UIView alloc]initWithFrame:CGRectMake(0, 30 + (KHEIGHT - 44) / 4, KWIDTH, 1)];
    _lView.backgroundColor = [UIColor lightGrayColor];
    [self.footView addSubview:_lView];
    
    [self.tableView setTableFooterView:_footView];
    _lView = [[UIView alloc]initWithFrame:CGRectMake(0, 30 + (KHEIGHT - 44) / 2 - 5, KWIDTH, 1)];
    _lView.backgroundColor = [UIColor lightGrayColor];
    [self.footView addSubview:_lView];
    
    [self.tableView setTableFooterView:_footView];
    _lView = [[UIView alloc]initWithFrame:CGRectMake(KWIDTH / 3, 30, 1, (KHEIGHT - 44) / 2 - 5)];
    _lView.backgroundColor = [UIColor lightGrayColor];
    [self.footView addSubview:_lView];
    
    [self.tableView setTableFooterView:_footView];
    _lView = [[UIView alloc]initWithFrame:CGRectMake(KWIDTH / 3 * 2, 30, 1, (KHEIGHT - 44) / 2 - 5)];
    _lView.backgroundColor = [UIColor lightGrayColor];
    [self.footView addSubview:_lView];
    
    UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(10, 40, KWIDTH / 3 - 20, KWIDTH / 3 - 20)];
    imageView1.image = [UIImage imageNamed:@"baiyibaishun"];
    [self.footView addSubview:imageView1];
    
    UIImageView *imageView2 = [[UIImageView alloc]initWithFrame:CGRectMake(10 + KWIDTH / 3, 40, KWIDTH / 3 - 20, KWIDTH / 3 - 20)];
    imageView2.image = [UIImage imageNamed:@"sanjiuyaoye"];
    [self.footView addSubview:imageView2];

    UIImageView *imageView3 = [[UIImageView alloc]initWithFrame:CGRectMake(10 + KWIDTH / 3 * 2, 40, KWIDTH / 3 - 20, KWIDTH / 3 - 20)];
    imageView3.image = [UIImage imageNamed:@"henrui"];
    [self.footView addSubview:imageView3];

    UIImageView *imageView4 = [[UIImageView alloc]initWithFrame:CGRectMake(10, 40 + (KHEIGHT - 44) / 4, KWIDTH / 3 - 20, KWIDTH / 3 - 20)];
    imageView4.image = [UIImage imageNamed:@"renhe"];
    [self.footView addSubview:imageView4];
    
    UIImageView *imageView5 = [[UIImageView alloc]initWithFrame:CGRectMake(10  + KWIDTH / 3, 40 + (KHEIGHT - 44) / 4, KWIDTH / 3 - 20, KWIDTH / 3 - 20)];
    imageView5.image = [UIImage imageNamed:@"zishengtang"];
    [self.footView addSubview:imageView5];

    UIImageView *imageView6 = [[UIImageView alloc]initWithFrame:CGRectMake(10 + KWIDTH / 3 * 2, 40 + (KHEIGHT - 44) / 4, KWIDTH / 3 - 20, KWIDTH / 3 - 20)];
    imageView6.image = [UIImage imageNamed:@"yunnanbaiyao"];
    [self.footView addSubview:imageView6];
    
}

#pragma mark --- 第一个Button方法 ---
- (void)oneButtonAction:(UIButton *)button
{
    // 跳转到扫描
    SweepViewController *sweep = [[SweepViewController alloc]init];
    [self.navigationController pushViewController:sweep animated:YES];
}


#pragma mark --- 第二个Button方法 ---
- (void)towButtonAction:(UIButton *)button
{
    ConsultViewController *consult = [[ConsultViewController alloc]init];
    [self.navigationController pushViewController:consult animated:YES];
}

#pragma mark --- 第三个Button方法 ---
- (void)threeButtonAction:(UIButton *)button
{
    RemindViewController *remind = [[RemindViewController alloc]init];
    [self.navigationController pushViewController:remind animated:YES];
}

#pragma mark --- 第四个Button方法 ---
- (void)fourButtonAction:(UIButton *)button
{
    FourButtonViewController *four = [[FourButtonViewController alloc]init];
    [self.navigationController pushViewController:four animated:YES];
}

#pragma mark --- 实现家庭药箱手势方法 ---
- (void)homeTapAction:(UIGestureRecognizer *)tap
{
   
    HomeImageViewController *home = [[HomeImageViewController alloc]init];
            _isOneOrTow = NO;
       home.isOneOrTow = _isOneOrTow;
        [self.navigationController pushViewController:home animated:YES];
}

#pragma mark --- 实现维生素手势方法 ---
- (void)vitaminTapTapAction:(UITapGestureRecognizer *)tap
{
     HomeImageViewController *home = [[HomeImageViewController alloc]init];
    _isOneOrTow = YES;
    home.isOneOrTow = _isOneOrTow;
    [self.navigationController pushViewController:home animated:YES];
}

#pragma mark --- 实现定时器的方法 ---
- (void)timerAction:(NSTimer *)timer
{
    // 记录当前的下标
    NSInteger index = _hadeScrollView.contentOffset.x / KWIDTH;
    [UIView animateWithDuration:0.3 animations:^{
        [_hadeScrollView setContentOffset:CGPointMake(KWIDTH * (index + 1), 0)];
        }];
       if (index == 4)
    {
        [_hadeScrollView setContentOffset:CGPointMake(0, 0)];
    }
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
